package com.yangchoi.jetpackcompose.utils

import android.os.Build
import java.util.Base64

object Base64Util {
    fun stringToBase64(input: String): String {
        val inputBytes = input.toByteArray()
        val encodedBytes = if (Build.VERSION.SDK_INT >= 26)
            Base64.getEncoder().encode(inputBytes)
        else
            android.util.Base64.encode(input.toByteArray(), android.util.Base64.DEFAULT)

        return String(encodedBytes)
    }

    fun base64ToString(input: String): String {
        val decodedBytes = if (Build.VERSION.SDK_INT >= 26) Base64.getDecoder().decode(input) else android.util.Base64.decode(input.toByteArray(), android.util.Base64.DEFAULT)
        return String(decodedBytes)
    }
}